package com.qf.config;

import com.qf.interceptor.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lixu  springmvc.xml
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {


    /**
     * 添加大量的拦截器
     * <mvc:interceptors>
     *  *          <mvc:interceptor>
     *  *              <interceptor mapping="/>
     *                 <bean class="MyInterceptor
     *  *          </mvc:interceptor>
     *  *      </mvc:interceptors>
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");
    }

    /**
     * 配置静态资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
       registry.addResourceHandler("/upload/**").addResourceLocations("/upload/");
       registry.addResourceHandler("/img/**").addResourceLocations("/img/");

       //   spring.resources.static-locations=classpath:/img/**
       //   spring.resources.static-locations=classpath:/js/**
       //   spring.resources.static-locations=classpath:/css/**
       //   spring.resources.static-locations=classpath:/upload/**
    }
}
